﻿using System;
using System.Collections.Generic;
using ZOIL.DataModel;

namespace Sample.PhotoBrowser.Components
{
    public class FlickrPhoto : InformationObjectBase
    {
        private string _title;
        private List<string> _tags;
        private string _userName;
        private string _realName;
        private string _userCountry;
        private string _description;
        private string _buddyIconUrl;
        private DateTime _dateUploaded;
        private int _views;
        private string _photoId;
        private string _smallUrl;

        public string Title
        {
            get { return _title; }
            set
            {
                if (value == _title)
                {
                    return;
                }
                _title = value;
                RaisePropertyChanged("Title");
                OnObjectLocallyChanged();
            }
        }

        //XmlSerializer mag IList nicht
        public List<string> Tags
        {
            get { return _tags; }
            set
            {
                if (Equals(value, _tags))
                {
                    return;
                }
                _tags = value;
                RaisePropertyChanged("Tags");
                OnObjectLocallyChanged();
            }
        }

        public string UserName
        {
            get { return _userName; }
            set
            {
                if (value == _userName)
                {
                    return;
                }
                _userName = value;
                RaisePropertyChanged("UserName");
                OnObjectLocallyChanged();
            }
        }

        public string RealName
        {
            get { return _realName; }
            set
            {
                if (value == _realName)
                {
                    return;
                }
                _realName = value;
                RaisePropertyChanged("RealName");
                OnObjectLocallyChanged();
            }
        }

        public string UserCountry
        {
            get { return _userCountry; }
            set
            {
                if (value == _userCountry)
                {
                    return;
                }
                _userCountry = value;
                RaisePropertyChanged("UserCountry");
                OnObjectLocallyChanged();
            }
        }

        public string Description
        {
            get { return _description; }
            set
            {
                if (value == _description)
                {
                    return;
                }
                _description = value;
                RaisePropertyChanged("Description");
                OnObjectLocallyChanged();
            }
        }

        public string BuddyIconUrl
        {
            get { return _buddyIconUrl; }
            set
            {
                if (Equals(value, _buddyIconUrl))
                {
                    return;
                }
                _buddyIconUrl = value;
                RaisePropertyChanged("BuddyIconUrl");
                OnObjectLocallyChanged();
            }
        }

        public DateTime DateUploaded
        {
            get { return _dateUploaded; }
            set
            {
                if (value.Equals(_dateUploaded))
                {
                    return;
                }
                _dateUploaded = value;
                RaisePropertyChanged("DateUploaded");
                OnObjectLocallyChanged();
            }
        }

        public int Views
        {
            get { return _views; }
            set
            {
                if (value == _views)
                {
                    return;
                }
                _views = value;
                RaisePropertyChanged("Views");
                OnObjectLocallyChanged();
            }
        }

        public string PhotoId
        {
            get { return _photoId; }
            set
            {
                if (value == _photoId)
                {
                    return;
                }
                _photoId = value;
                RaisePropertyChanged("PhotoId");
                OnObjectLocallyChanged();
            }
        }

        //Uri ist nicht per XmlSerializer serializierbar -> string mit url
        public string SmallUrl
        {
            get { return _smallUrl; }
            set
            {
                if (Equals(value, _smallUrl))
                {
                    return;
                }
                _smallUrl = value;
                RaisePropertyChanged("SmallUrl");
                OnObjectLocallyChanged();
            }
        }

        #region Overrides of InformationObjectBase

        public override void OnRemoteUpdated()
        {
            base.OnRemoteUpdated();

            RaisePropertyChanged("BuddyIconUrl");
            RaisePropertyChanged("DatabaseId");
            RaisePropertyChanged("DateUploaded");
            RaisePropertyChanged("Description");
            RaisePropertyChanged("PhotoId");
            RaisePropertyChanged("RealName");
            RaisePropertyChanged("SmallUrl");
            RaisePropertyChanged("Tags");
            RaisePropertyChanged("Title");
            RaisePropertyChanged("UserCountry");
            RaisePropertyChanged("UserName");
            RaisePropertyChanged("Views");
        }

        #endregion

        /// <summary>
        /// Returns a string that represents the current object.
        /// </summary>
        /// <returns>
        /// A string that represents the current object.
        /// </returns>
        public override string ToString()
        {
            return string.Format("DatabaseId: {3}, PhotoId: {0}, Title: {1}, UserName: {2}", PhotoId, Title, UserName, DatabaseId);
        }
    }
}